#import "EaseOptionsMessageCell.h"
@implementation EaseOptionsMessageCell
+ (void)initialize
{
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.accessibilityIdentifier = @"table_cell1";
        [self _setupSubviews];
    }
    return self;
}
-(void)tapAvatar{
    if (_selectAvart) {
        _selectAvart();
    }
}
- (void)_setupSubviews
{
    self.backgroundColor = m1_bg_color;
    _avatarView = [[UIImageView alloc] init];
    _avatarView.frame = CGRectMake(10, 10, 40, 40);
    _avatarView.clipsToBounds = YES;
    _avatarView.layer.cornerRadius = 20;
    _avatarView.userInteractionEnabled = YES;
    _avatarView.contentMode = UIViewContentModeScaleAspectFill;
    _avatarView.backgroundColor = [UIColor m1_colorHex:0xEC6B71];
    [self.contentView addSubview:_avatarView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatar)];
    [_avatarView addGestureRecognizer:tap];
    _bubbleView = [[UIImageView alloc]init];
    _bubbleView.frame = CGRectMake(_avatarView.frame.origin.x+_avatarView.frame.size.width+10, 10, 200, 100);
    _bubbleView.image = [[UIImage imageNamed:@"EaseUIResource.bundle/chat_receiver_bg"] stretchableImageWithLeftCapWidth:22 topCapHeight:20];
    _bubbleView.userInteractionEnabled = YES;
    [self.contentView addSubview:_bubbleView];
    [_bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(60);
        make.top.offset(10);
        make.width.mas_offset(200);
        make.bottom.offset(-10);
    }];
    _textLB = [[UILabel alloc] initWithFrame:CGRectZero];
    _textLB.numberOfLines = 0;
    _textLB.lineBreakMode = NSLineBreakByWordWrapping;
    _textLB.backgroundColor = [UIColor clearColor];
    _textLB.font = m1_font(15);
    _textLB.frame = CGRectMake(15, 0, 175, 50);
    [_bubbleView addSubview:_textLB];
    [_textLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-10);
        make.top.offset(8);
    }];
    _refuseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _refuseBtn.frame = CGRectZero;
    _refuseBtn.titleLabel.font = m1_font(15);
    [_refuseBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_refuseBtn setTitle:@"拒绝" forState:UIControlStateNormal];
    _refuseBtn.tag = 0;
    [_refuseBtn setBackgroundColor:[UIColor m1_colorHex:0x333333]];
    _refuseBtn.frame = CGRectMake(6, _bubbleView.frame.size.height-31, 96.5, 30);
    [_bubbleView addSubview:_refuseBtn];
    [_refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(3);
        make.bottom.offset(-1);
        make.size.mas_offset(CGSizeMake(97, 30));
    }];
    _acceptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _acceptBtn.titleLabel.font = m1_font(15);
    _acceptBtn.frame = CGRectZero;
    [_acceptBtn setBackgroundColor:[UIColor m1_colorHex:0xE5686E]];
    [_acceptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_acceptBtn setTitle:@"同意" forState:UIControlStateNormal];
    _acceptBtn.tag = 1;
     _acceptBtn.frame = CGRectMake(_refuseBtn.frame.origin.x+_refuseBtn.frame.size.width, _bubbleView.frame.size.height-31, 97, 30);
    [_bubbleView addSubview:_acceptBtn];
    [_acceptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_refuseBtn.mas_right);
        make.bottom.offset(-1);
        make.size.mas_offset(CGSizeMake(97, 30));
    }];
    _line = [[UIView alloc]init];
    _line.backgroundColor = [UIColor whiteColor];
    [self addSubview:_line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_refuseBtn.mas_right).offset(-1);
        make.top.equalTo(_refuseBtn.mas_top);
        make.bottom.equalTo(_refuseBtn.mas_bottom);
        make.width.mas_offset(1);
    }];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_acceptBtn.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(10,10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _acceptBtn.bounds;
    maskLayer.path = maskPath.CGPath;
    self.acceptBtn.layer.mask = maskLayer;
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:_refuseBtn.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(10,10)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = _refuseBtn.bounds;
    maskLayer1.path = maskPath1.CGPath;
    self.refuseBtn.layer.mask = maskLayer1;
}
-(void)setModel:(id<IMessageModel>)model{
    _model = model;
    _textLB.text = model.text;

    if ([[model.message.ext m1_stringKey:@"hx_attr_exchange_wx"] boolValue]) {
        _textLB.text = @"我想要与你交换微信，您是否同意？";
    }
    if (model.avatarURLPath) {
        [self.avatarView sd_setImageWithURL:[NSURL URLWithString:model.avatarURLPath] placeholderImage:model.avatarImage];
    } else {
        self.avatarView.image = model.avatarImage;
    }
    BOOL canoption = NO;
    if ([[model.message.ext m1_stringKey:@"hx_attr_exchange_wx_enable"] boolValue]) {
        canoption = YES;
    }
    if (!canoption) {
        [self.refuseBtn setBackgroundColor:[UIColor m1_colorHex:0xbfbfbf]];
        [self.acceptBtn setBackgroundColor:[UIColor m1_colorHex:0xbfbfbf]];
        self.refuseBtn.userInteractionEnabled = NO;
        self.acceptBtn.userInteractionEnabled = NO;
        _line.backgroundColor = [UIColor whiteColor];
    }else{
        [self.acceptBtn setBackgroundColor:[UIColor m1_colorHex:0xE5686E]];
        [self.refuseBtn setBackgroundColor:[UIColor m1_colorHex:0x333333]];
        self.refuseBtn.userInteractionEnabled = YES;
        self.acceptBtn.userInteractionEnabled = YES;
        _line.backgroundColor = [UIColor m1_colorHex:0x333333];
    }
}
- (BOOL)canBecomeFirstResponder
{
    return YES;
}
+ (NSString *)cellIdentifierWithModel:(id<IMessageModel>)model
{
    return @"EaseOptionsMessageCell";
}
+ (CGFloat)cellHeightWithModel:(id<IMessageModel>)model
{
    NSString *str = @"";
    if ([[model.message.ext m1_stringKey:@"hx_attr_exchange_wx"] boolValue]) {
        str = @"我想要与你交换微信，您是否同意？";
    }
    CGSize size = [str m1_size_With_Font:m1_font(15) constrainedToSize:CGSizeMake(175, MAXFLOAT)];
    return size.height+74;
}
- (void)awakeFromNib {

    [super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];
}
@end
